﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace h1
{
    public partial class Form_getUser : Form
    {
        public Form_getUser()
        {
            InitializeComponent();
        }
        public Form_getUser(int type,string user)
        {
            InitializeComponent();
            comboBox1.SelectedIndex = type;
            textBox2.Text=user;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "")
            {
                errorProvider1.SetError(textBox2, "请输入ID或用户名！");
            }
            else
            {
                errorProvider1.Clear();
                DataSet ds = MySqlHelper.getDataSet(MySqlHelper.Conn, "SELECT * FROM users");
                string item;
                string item2;
                if (comboBox1.SelectedIndex == 0)
                {
                    item = "userName";
                    item2 = "用户名";
                }
                else
                {
                    item = "userID";
                    item2 = "用户ID";
                }
                DataRow[] rows = ds.Tables[0].Select($"{item}='{textBox2.Text}'");
                if (rows.Count() < 1)
                {
                    Form_message form_Message = new Form_message("查询失败", $"{item2}为{textBox2.Text}的用户不存在！请重新输入！");
                    form_Message.ShowDialog();
                }
                else if (rows[0]["userQuestion"].ToString() == "")
                {
                    Form_message form_Message = new Form_message("查询失败", $"{item2}为{textBox2.Text}的用户还没有设置密保问题！");
                    form_Message.ShowDialog();
                }
                else
                {
                    Form_mibao form_Mibao = new Form_mibao(rows[0]["userQuestion"].ToString(), rows[0]["userAnswere"].ToString(), rows[0]["userNote"].ToString(), $"正在找回账号——{item2}:{textBox2.Text}", $"{item}='{textBox2.Text}'");
                    form_Mibao.ShowDialog();
                    this.Close();
                }
            }
        }
    }
}
